<?php

// Database remota dbadmin.grupotarde.com // user:dawg3dbuser // pass: x8it6rMzAY

//https://www.google.com/webmasters/tools/home?hl=es   // cuenta:moviwebv3@gmail.com // pass: pue123456

class	Entrada	extends	CI_Controller	{

				public	function	index()	{
								$this->login();
				}

				public	function	login()	{
								$data['flag']	=	0;

								if	(!isset($_POST['maillogin']))	{
												$this->load->view('login',	$data);
								}	else	{
												$this->form_validation->set_rules('maillogin',	'e-mail',	'required|valid_email');
												$this->form_validation->set_rules('passlogin',	'password',	'required');
												if	(($this->form_validation->run()	==	FALSE))	{
																$data['flag']	=	1;
																$this->load->view('login',	$data);
												}	else	{
																$this->load->model('usuarios_model');
																$loginok	=	$this->usuarios_model->ValidarUsuario($_POST['maillogin'],	$_POST['passlogin']);
																if	($loginok)	{
																				$this->session->set_userdata('user',$loginok->nombre);
																				$this->escritorio();
																}	else	{
																				$data['flag']	=	1;
																				$data['error']	=	"E-mail o password incorrecta, por favor vuelva a intentar";
																				$this->load->view('login',	$data);
																}
												}
								}
				}

				public	function	escritorio()	{
								$data['titulo']	=	'Panel de Control';
								$data['subtitulo']	=	'Pagina Principal';
								$this->load->view('includes/header');
								$this->load->view('escritorio',	$data);
								$this->load->view('includes/footer');
				}

				public	function	logout()	{
								$this->session->sess_destroy();
								$this->login();
				}

}
